<?php
namespace Content\Classes;
use Think\Controller;
class content_output{
	var $fields;
	var $data;

	function __construct($modelid) {
		$this->modelid = $modelid;
		$this->fields = $this->_get_fields($modelid);
    }
	private function _get_fields($modelid)
	{
		$data=M('content_model_field')->where(array('modelid'=>$modelid))->select();
		$fields=array();
		foreach($data as $v)
		{
			$fields[$v['field']]=$v;
		}
		return $fields;
	}	
	function get($data) {
		$this->data = $data;
		$this->id = $data['id'];
		$info = array();
		foreach($this->fields as $field=>$v) {		
			if(!isset($data[$field])) continue;
			$func = $v['formtype'];
			$value = $data[$field];
			$result = method_exists($this, $func) ? $this->$func($field, $data[$field]) : $data[$field];
			if($result !== false) $info[$field] = $result;
		}
		return $info;
	}
	function images($field, $value) {
		return explode('@#|',safe_replace($value));
	}
	function downfiles($field, $value) {
		return string2array(stripslashes(new_html_entity_decode($value)));	
	} 
}
?>